#!/bin/bash

SERV_TELNET_DIR="openbsd-inetd"

if [ $UID != 0 ]; then
    echo "Debe estar logueado como Superusuario para levantar este servicio."
    exit 1
fi

# /24 = 0
# /25 = 128
# /26 = 192
# /27 = 224
# /28 = 240
# /29 = 248
# /30 = 252

echo "Cargando tabla ruteo"
# Pertenece a Lex Luthor y Magneto
# Por Lex Luthor, tap7
# Idem host B

# Salen por R16:
# Red Aquaman
route add -net 194.210.31.0 netmask 255.255.255.0 gw 10.58.5.1 tap7

# Red Batman
route add -net 10.58.6.224 netmask 255.255.255.240 gw 10.58.5.1 tap7

# Red Catwoman
route add -net 10.58.7.128 netmask 255.255.255.192 gw 10.58.5.1 tap7

# Red Emma Frost
route add -net 10.58.7.192 netmask 255.255.255.240 gw 10.58.5.1 tap7

# Red Flash
route add -net 10.111.25.0 netmask 255.255.255.128 gw 10.58.5.1 tap7

# Red Green Lantern
route add -net 10.111.25.128 netmask 255.255.255.128 gw 10.58.5.1 tap7

# Red Magneto
route add -net 10.158.6.128 netmask 255.255.255.224 gw 10.58.5.1 tap7

# Red Quicksilver
route add -net 10.58.6.192 netmask 255.255.255.224 gw 10.58.5.1 tap7

#
# Salen por R17:
# Red Joker
route add -net 10.58.6.160 netmask 255.255.255.224 gw 10.58.5.2 tap7

# Redes NightCrawler
route add -net 10.58.7.216 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.220 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.224 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.228 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.232 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.236 netmask 255.255.255.252 gw 10.58.5.2 tap7
route add -net 10.58.7.240 netmask 255.255.255.252 gw 10.58.5.2 tap7

# Por Magneto, tap6
# Salen por R14:
# Red Emma Frost
route add -net 10.58.7.192 netmask 255.255.255.240 gw 10.58.6.130 tap6

# Red Flash
route add -net 10.111.25.0 netmask 255.255.255.128 gw 10.58.6.130 tap6

# Red Green Lantern
route add -net 10.111.25.128 netmask 255.255.255.128 gw 10.58.6.130 tap6

# Salen por R15:
# Red Aquaman
route add -net 194.210.31.0 netmask 255.255.255.0 gw 10.58.6.131 tap6

# Red Batman
route add -net 10.58.6.224 netmask 255.255.255.240 gw 10.58.6.131 tap6

# Red Catwoman
route add -net 10.58.7.128 netmask 255.255.255.192 gw 10.58.6.131 tap6

# Red Quicksilver
route add -net 10.58.6.192 netmask 255.255.255.224 gw 10.58.6.131 tap6

# Salen por R16:
# Red Lex Luthor
route add -net 10.58.5.0 netmask 255.255.255.0 gw 10.58.6.132 tap6

# Red Joker
route add -net 10.58.6.160 netmask 255.255.255.224 gw 10.58.6.132 tap6

# Redes NightCrawler
route add -net 10.58.7.216 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.220 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.224 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.228 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.232 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.236 netmask 255.255.255.252 gw 10.58.6.132 tap6
route add -net 10.58.7.240 netmask 255.255.255.252 gw 10.58.6.132 tap6

echo "Tabla ruteo cargada"


echo "Inicialización de Servicio Telnet"
echo "*********************************"
echo ""
echo "Instalando Servicio"
echo ""
apt-get install -y telnetd

echo ""
echo "Configurando Servicio"
echo ""

service $SERV_TELNET_DIR stop

cp ./inetd.conf /etc

service $SERV_TELNET_DIR start

echo ""
echo "Fin de Inicialización de Servicio FTP"
echo "*************************************"
